package org.springblade.modules.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.modules.admin.entity.EstateElevatorUser;
import org.springblade.modules.admin.vo.EstateSelectUserVO;
import org.springblade.modules.system.vo.SimpleUserVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.admin.entity.EstateElevatorSafeUser;
import org.springblade.modules.admin.mapper.EstateElevatorSafeUserMapper;
import org.springblade.modules.admin.service.EstateElevatorSafeUserService;
@Service
public class EstateElevatorSafeUserServiceImpl extends BaseServiceImpl<EstateElevatorSafeUserMapper, EstateElevatorSafeUser> implements EstateElevatorSafeUserService{

	private boolean removeElevatorUser(List<Long> elevatorIds) {
		return remove(Wrappers.<EstateElevatorSafeUser>lambdaQuery().in(EstateElevatorSafeUser :: getElevatorId, elevatorIds));
	}

	@Override
	public Boolean safe(EstateSelectUserVO selectUserVO) {
		List<EstateElevatorSafeUser> savaList = new ArrayList<>();
		List<Long> elevatorIds = selectUserVO.getElevatorIds();
		// 删除已分配的人员
		this.removeElevatorUser(elevatorIds);
		for (Long elevatorId : elevatorIds) {
			for (SimpleUserVO userInfo : selectUserVO.getUserInfos()) {
				EstateElevatorSafeUser estateElevatorUser = new EstateElevatorSafeUser();
				estateElevatorUser.setElevatorId(elevatorId);
				estateElevatorUser.setUserId(userInfo.getUserId());
				estateElevatorUser.setUserName(userInfo.getUserName());
				savaList.add(estateElevatorUser);
			}
		}
		return this.saveBatch(savaList);
	}
}
